<script>
	import Vue from 'vue'
	import storage from '@/common/js/storage';
	let __timerId = 0;
	export default {
		onLaunch: async function() {
			uni.getSystemInfo({
				success: e=> {
					this.initSize(e);
				}
			})
			// 获取登录信息
			uni.login({
			    provider: 'weixin',
			    success: async (res) => {
			        this.$store.commit('setCode', res.code)
					await this.initLogin();
			    },
			});
			
			// 获取用户授权信息
			wx.getSetting({
				success: (res) => {
					let authLocation = res.authSetting['scope.userLocation']
					let status = -1
					if(authLocation == undefined) {
						status = -1
					} else if(authLocation) {
						status = 1
					} else {
						status = 0
					}
					this.$store.commit('setLocation', status);
				}
			})
			// 查询字典类型列表
			this.$u.get('/public/dict/queryAppDicTypeList').then(res => {
				this.$store.commit('setDicTypeList',res)
			})
			
			this.$u.get('/public/wisper/getBusinessParamSetting').then(res => {
				this.$store.commit('setConfig',res)
				
			})
		},
		methods: {
			//登录状态
			async initLogin(){
				await this.$u.get('/paopao/mini/user/getUsersInfo').then((data) => {
					if(!data || data.status == -1) { return }
					// console.log(data)
					if(data.status === 2000) {
						storage.clear()
						this.$store.commit('clearUserInfo')
					} else {
						storage.set('userInfo', data);
						this.$store.commit('setUserInfo', data)
					}
				});
			},
			/**
			 * 存储设备信息 参考colorUI
			 * @param {Object} 
			 */
			initSize(e){
				const systemInfo = e;
				let navigationBarHeight;
				let custom = {};
				// #ifndef MP
				custom = {height: 36,width: 88};
				navigationBarHeight = 44;
				// #endif
				// #ifdef MP
				custom = wx.getMenuButtonBoundingClientRect();
				navigationBarHeight = custom.bottom + custom.top - e.statusBarHeight * 2;
				// #endif	
				systemInfo.custom = custom;
				systemInfo.navigationBarHeight = navigationBarHeight;
				Vue.prototype.systemInfo = systemInfo;
			},
			//打开全局定时器
			openTimer(){
				this.closeTimer();
				__timerId = setInterval(()=>{
					this.$store.commit('setStateAttr', {
						key: 'timerIdent',
						val: !this.$store.state.timerIdent
					})
				}, 1000)
			},
			//关闭定时器
			closeTimer(){
				if(__timerId != 0){
					clearInterval(__timerId);
					__timerId = 0;
				}
			},
		},
		onShow: function() {
			this.openTimer();
		},
		onHide: function() {
			this.closeTimer();
		}
	}
</script>

<style lang="less">
	/*每个页面公共css */
	@import url("./common/css/common.css");
</style>
